package com.vf.admin.miaodong.controller;

import com.vf.admin.client.service.VipPackageService;
import com.vf.admin.common.BaseController;
import com.vf.admin.common.entity.Result;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.VipPackage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/after/vip")
public class AfterVipPackageController extends BaseController {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    VipPackageService vipPackageService;

    @RequestMapping("/list")
    public String list(SplitPageBean splitPageBean) {
        try {
            Map<String, Object> map = new HashMap<>();
            List<VipPackage> list = vipPackageService.page(map, splitPageBean);

            request.setAttribute("list", list);
            request.setAttribute("splitPage", splitPageBean);
            return this.sucess("/web/after/vip/list");
        } catch (Exception e) {
            logger.error("查询兑换管理列表异常", e);
            return this.error("系统繁忙");
        }
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Result saveOrUpdate(VipPackage params) {
        try {
            vipPackageService.saveOrUpdate(params);
            return sucessJSON("成功");
        } catch (Exception e) {
            return errorJSON("系统繁忙");
        }
    }

    @RequestMapping("/info")
    public String info(Integer id) {
        try {
            VipPackage info = vipPackageService.info(id);
            request.setAttribute("obj", info);
            return this.sucess("/web/after/vip/edit");
        } catch (Exception e) {
            return this.error("系统繁忙");
        }
    }

    @ResponseBody
    @RequestMapping("/del")
    public Result del(Integer id) {
        vipPackageService.del(id);
        return sucessJSON("成功");
    }

    @RequestMapping("/gotoAdd")
    public String gotoAdd() {
        return this.sucess("/web/after/vip/add");
    }
}
